<template>
  <div>
    <zh-card title="">
      <zh-form :model="pageData.queryParams" ref="queryFormRef">
        <zh-form-input prop="interfaceId" label="动态接口主键" type="text" :span="8" dataType="common"
                       v-model="pageData.queryParams.interfaceId"></zh-form-input>
        <zh-form-input prop="interfaceName" label="接口名称" type="text" :span="8" dataType="common"
                       v-model="pageData.queryParams.interfaceName"></zh-form-input>
        <zh-form-input prop="interfaceDescription" label="接口描述" type="text" :span="8" dataType="common"
                       v-model="pageData.queryParams.interfaceDescription"></zh-form-input>
        <zh-form-input prop="paramTypeId" label="接口入参类型id" type="text" :span="8" dataType="common"
                       v-model="pageData.queryParams.paramTypeId"></zh-form-input>
        <zh-form-input prop="resultTypeId" label="接口出参类型id" type="text" :span="8" dataType="common"
                       v-model="pageData.queryParams.resultTypeId"></zh-form-input>
        <zh-form-input prop="CREATENAME" label="创建人" type="text" :span="8" dataType="common"
                       v-model="pageData.queryParams.CREATENAME"></zh-form-input>
        <zh-form-input prop="CREATETIME" label="创建时间" type="text" :span="8" dataType="common"
                       v-model="pageData.queryParams.CREATETIME"></zh-form-input>
        <zh-form-input prop="UPDATENAME" label="修改人" type="text" :span="8" dataType="common"
                       v-model="pageData.queryParams.UPDATENAME"></zh-form-input>
        <zh-form-input prop="UPDATETIME" label="更新时间" type="text" :span="8" dataType="common"
                       v-model="pageData.queryParams.UPDATETIME"></zh-form-input>
        <zh-form-input prop="DEL" label="逻辑删除标志 0 正常 1 删除" type="text" :span="8" dataType="common"
                       v-model="pageData.queryParams.DEL"></zh-form-input>
        <zh-form-query @queryClick="queryDynamicLogicInterface" :formRef="queryFormRef" :show-advanced="false">
          <el-button @click="showAddDialog">添加</el-button>
        </zh-form-query>
      </zh-form>
    </zh-card>
    <zh-table title="动态逻辑接口列表" ref="dynamicLogicInterfaceTable"
              size="mini"
              :funcCode="'dynamicLogicInterface0001'"
              :columns="pageData.tableColumns"
              highlight-current-row>
      <template #op="scope">
        <el-tooltip content="编辑" placement="top">
          <el-button :icon="Edit" link @click="showEditDialog(scope)"></el-button>
        </el-tooltip>
        <el-tooltip content="删除" placement="top">
          <el-button :icon="Delete" type="danger" link @click="delDynamicLogicInterface(scope.row)"></el-button>
        </el-tooltip>
        <el-tooltip content="详情" placement="top">
          <el-button :icon="Document" link @click="showDetail(scope)"></el-button>
        </el-tooltip>
        <el-tooltip content="执行" placement="top">
          <el-button :icon="Document" link @click="exec(scope.row)"></el-button>
        </el-tooltip>
      </template>
    </zh-table>
    <el-dialog title="添加动态逻辑接口" v-model="pageData.addDynamicLogicInterfaceDialogVisible">
      <zh-form :rules="pageData.formRules">
        <zh-form-input prop="interfaceId" label="动态接口主键" type="text" :span="8" dataType="common"
                       v-model="pageData.formData.interfaceId"></zh-form-input>
        <zh-form-input prop="interfaceName" label="接口名称" type="text" :span="8" dataType="common"
                       v-model="pageData.formData.interfaceName"></zh-form-input>
        <zh-form-input prop="interfaceDescription" label="接口描述" type="text" :span="8" dataType="common"
                       v-model="pageData.formData.interfaceDescription"></zh-form-input>
        <zh-form-input prop="paramTypeId" label="接口入参类型id" type="text" :span="8" dataType="common"
                       v-model="pageData.formData.paramTypeId"></zh-form-input>
        <zh-form-input prop="resultTypeId" label="接口出参类型id" type="text" :span="8" dataType="common"
                       v-model="pageData.formData.resultTypeId"></zh-form-input>
        <zh-form-input prop="CREATENAME" label="创建人" type="text" :span="8" dataType="common"
                       v-model="pageData.formData.CREATENAME"></zh-form-input>
        <zh-form-input prop="CREATETIME" label="创建时间" type="text" :span="8" dataType="common"
                       v-model="pageData.formData.CREATETIME"></zh-form-input>
        <zh-form-input prop="UPDATENAME" label="修改人" type="text" :span="8" dataType="common"
                       v-model="pageData.formData.UPDATENAME"></zh-form-input>
        <zh-form-input prop="UPDATETIME" label="更新时间" type="text" :span="8" dataType="common"
                       v-model="pageData.formData.UPDATETIME"></zh-form-input>
        <zh-form-input prop="DEL" label="逻辑删除标志 0 正常 1 删除" type="text" :span="8" dataType="common"
                       v-model="pageData.formData.DEL"></zh-form-input>
      </zh-form>
      <template #footer>
        <span class="dialog-footer">

          <el-button @click="pageData.addDynamicLogicInterfaceDialogVisible = false">取消</el-button>
          <el-button type="primary" @click="addDynamicLogicInterface">
            保存
          </el-button>
        </span>
      </template>
    </el-dialog>
    <el-dialog title="修改动态逻辑接口" v-model="pageData.editDynamicLogicInterfaceDialogVisible">
      <zh-form :rules="pageData.formRules">
        <zh-form-input prop="interfaceId" label="动态接口主键"
                       v-model="pageData.editFormData.interfaceId"></zh-form-input>
        <zh-form-input prop="interfaceName" label="接口名称"
                       v-model="pageData.editFormData.interfaceName"></zh-form-input>
        <zh-form-input prop="interfaceDescription" label="接口描述"
                       v-model="pageData.editFormData.interfaceDescription"></zh-form-input>
        <zh-form-input prop="paramTypeId" label="接口入参类型id"
                       v-model="pageData.editFormData.paramTypeId"></zh-form-input>
        <zh-form-input prop="resultTypeId" label="接口出参类型id"
                       v-model="pageData.editFormData.resultTypeId"></zh-form-input>
        <zh-form-input prop="CREATENAME" label="创建人"
                       v-model="pageData.editFormData.CREATENAME"></zh-form-input>
        <zh-form-input prop="CREATETIME" label="创建时间"
                       v-model="pageData.editFormData.CREATETIME"></zh-form-input>
        <zh-form-input prop="UPDATENAME" label="修改人"
                       v-model="pageData.editFormData.UPDATENAME"></zh-form-input>
        <zh-form-input prop="UPDATETIME" label="更新时间"
                       v-model="pageData.editFormData.UPDATETIME"></zh-form-input>
        <zh-form-input prop="DEL" label="逻辑删除标志 0 正常 1 删除"
                       v-model="pageData.editFormData.DEL"></zh-form-input>
      </zh-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="pageData.editDynamicLogicInterfaceDialogVisible = false">取消</el-button>
          <el-button type="primary" @click="editDynamicLogicInterface">
            保存
          </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script lang="ts" setup name="dynamicLogicInterface">
import {Delete, Edit, Document} from '@element-plus/icons-vue'
import {ElMessageBox} from "element-plus";
// ------------------接收传入参数(组件)-------------------

// ------------------钩子函数----------------------------
// 初始化
onMounted(() => {
  init();
})

// ------------------定义子组件--------------------------
const dynamicLogicInterfaceTable = ref();
const queryFormRef = ref();
// ------------------变量区------------------------------
const pageData = reactive({
  addDynamicLogicInterfaceDialogVisible: false,
  editDynamicLogicInterfaceDialogVisible: false,
  detailDialog: false,
  tableColumns: [
    {type: 'seq', width: 60, fixed: 'left', align: 'center', title: '序号'},
    {field: 'interfaceId', title: '动态接口主键', visible: false, align: 'center', width: 100},
    {field: 'interfaceName', title: '接口名称', visible: false, align: 'center', width: 100},
    {field: 'interfaceDescription', title: '接口描述', visible: true, align: 'center', width: 200},
    {field: 'paramTypeId', title: '接口入参类型id', visible: true, align: 'center', width: 100},
    {field: 'resultTypeId', title: '接口出参类型id', visible: true, align: 'center', width: 100},
    {field: 'CREATENAME', title: '创建人', visible: false, align: 'center', width: 100},
    {field: 'CREATETIME', title: '创建时间', visible: false, align: 'center', width: 100},
    {field: 'UPDATENAME', title: '修改人', visible: false, align: 'center', width: 100},
    {field: 'UPDATETIME', title: '更新时间', visible: false, align: 'center', width: 100},
    {field: 'DEL', title: '逻辑删除标志 0 正常 1 删除', visible: false, align: 'center', width: 100},
    {field: 'op', title: '操作', visible: true, align: 'center', width: 150, fixed: 'right', slots: {default: 'op'}},
  ],
  queryParams: {
    interfaceId: '',
    interfaceName: '',
    interfaceDescription: '',
    paramTypeId: '',
    resultTypeId: '',
    CREATENAME: '',
    CREATETIME: '',
    UPDATENAME: '',
    UPDATETIME: '',
    DEL: ''
  },
  formData: {
    interfaceId: '',
    interfaceName: '',
    interfaceDescription: '',
    paramTypeId: '',
    resultTypeId: '',
    CREATENAME: '',
    CREATETIME: '',
    UPDATENAME: '',
    UPDATETIME: '',
    DEL: ''
  },
  editFormData: {
    interfaceId: '',
    interfaceName: '',
    interfaceDescription: '',
    paramTypeId: '',
    resultTypeId: '',
    CREATENAME: '',
    CREATETIME: '',
    UPDATENAME: '',
    UPDATETIME: '',
    DEL: ''
  },
  formRules: {},
  dictFields: '',
  dictData: [],
});
// ------------------方法区------------------------------
const init = () => {
  getDict();
  queryDynamicLogicInterface();
}
// 查询数据字典信息
const getDict = () => {
  let params = {
    dictFields: pageData.dictFields,
  };
  $api.common.getBatchDict.post(params).then((res: any) => {
    pageData.dictData = res.result;
  });
};
const queryDynamicLogicInterface = () => {
  dynamicLogicInterfaceTable.value.query(pageData.queryParams);
}
const showAddDialog = () => {
  pageData.addDynamicLogicInterfaceDialogVisible = true;
  pageData.formData = {
    interfaceId: '',
    interfaceName: '',
    interfaceDescription: '',
    paramTypeId: '',
    resultTypeId: '',
    CREATENAME: '',
    CREATETIME: '',
    UPDATENAME: '',
    UPDATETIME: '',
    DEL: ''
  }
}
const showEditDialog = (scope) => {
  pageData.editDynamicLogicInterfaceDialogVisible = true;
  pageData.editFormData = {...scope.row}
}
const addDynamicLogicInterface = () => {
  $api.common.send.post('dynamicLogicInterface0004', pageData.formData).then(res => {
    if (res.code == 0) {
      ElMessageBox.alert('添加动态逻辑接口成功');
      pageData.addDynamicLogicInterfaceDialogVisible = false;
      queryDynamicLogicInterface();
    }
  })
}
const editDynamicLogicInterface = () => {
  $api.common.send.post('dynamicLogicInterface0005', pageData.editFormData).then(res => {
    if (res.code == 0) {
      ElMessageBox.alert('修改动态逻辑接口成功');
      pageData.editDynamicLogicInterfaceDialogVisible = false;
      queryDynamicLogicInterface();
    }
  })
}
const delDynamicLogicInterface = ({interfaceId}) => {
  ElMessageBox.confirm('确定删除该动态逻辑接口?').then(() => {
    $api.common.send.post('dynamicLogicInterface0006', {interfaceId: interfaceId}).then(res => {
      if (res.code == 0) {
        ElMessageBox.alert('删除动态逻辑接口成功');
        queryDynamicLogicInterface();
      }
    })
  })
}

const exec = ({interfaceId}) => {
  $api.common.send.post('dynamicLogicInterface0007', {interfaceId: interfaceId}).then(res => {
    if (res.code == 0) {
      ElMessageBox.alert('执行动态逻辑接口成功');
      // queryDynamicLogicInterface();
    }
  })
}

</script>
<style lang="scss" scoped></style>
